package com.yoso.base.service;

import com.yoso.base.entity.BaseEntity;
import com.yoso.base.infrastructure.factory.BeanFactory;
import com.yoso.base.interfaces.vo.BaseVo;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhizejin
 */
public abstract class AbstractBaseService<E extends BaseEntity, V extends BaseVo, M extends BaseEntityExample> extends AbstractService implements IBaseService<V, M> {

    public abstract E V2E(V data);

    public abstract V E2V(E data);

    public List<E> bachV2E(Iterable<V> vs) {
        List<E> result = new ArrayList<>();
        vs.forEach(e -> result.add(V2E(e)));
        return result;
    }

    public List<V> bachE2V(Iterable<E> es) {
        List<V> result = new ArrayList<>();
        es.forEach(e -> result.add(E2V(e)));
        return result;
    }

    public <T> T convert(Object source, Class<T> target) {
        return BeanFactory.convertBean(source, target);
    }
}
